package lc20240624;

import java.util.HashMap;
import java.util.Map;

public class OnlyAppearTwiceNum {
    public int singleNumber(int[] nums) {
        if(nums.length==1){
            return nums[0];
        }
        Map<Integer,Integer> map=new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i],map.getOrDefault(nums[i],0)+1);
        }
        for (Integer i : map.keySet()) {
            if (map.get(i)==1){
                return i;
            }
        }
        return 0;
    }

    public static int singleNumber1(int[] nums) {
        int res=0;
        for (int i=0;i<nums.length;i++) {
            res=res^nums[i];
        }
        return res;
    }

    public static void main(String[] args) {
        int[] nums={2,4,2,3,4};
        System.out.println(singleNumber1(nums));
    }
}
